// pages/finance/loanPlan.js
import config from '../../config.js';
const base = config;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    carPrice: '',
    decoratePrice: 0,
    tel: '',
    paymentRatio: 0,
    name: '',
    ratioList: [0, 5, 10, 15, 20],
    ratioIndex: 0,
    user: {}
  },

  carPriceInput(e) {
    var value = e.detail.value;
    this.setData({
      carPrice: value
    })
  },

  decoratePriceInput(e) {
    var value = e.detail.value;
    this.setData({
      decoratePrice: value
    })
  },

  paymentRatioInput(e) {
    var value = e.detail.value;
    this.setData({
      ratioIndex: value,
      paymentRatio: this.data.ratioList[ratioIndex]
    })
  },
  ratioChange: function(e) {
    var value = e.detail.value;
    console.log(e);
    this.setData({
      ratioIndex: value,
      paymentRatio: this.data.ratioList[value]
    })
  },
  nameInput(e) {
    var value = e.detail.value;
    this.setData({
      name: value
    })
  },

  telInput(e) {
    var value = e.detail.value;
    this.setData({
      tel: value
    })
  },

  submit() {
    var name = this.data.name,
      tel = this.data.tel,
      carPrice = this.data.carPrice,
      paymentRatio = this.data.paymentRatio,
      decoratePrice = this.data.decoratePrice;
    if (!carPrice) {
      wx.showToast({
        title: '请输入裸车价格',
        icon: 'none',
      })
      return;
    }
    if (decoratePrice==null) {
      wx.showToast({
        title: '请输入装潢价格',
        icon: 'none',
      })
      return;
    }
    if (paymentRatio==null) {
      wx.showToast({
        title: '请输入首付比例',
        icon: 'none',
      })
      return;
    }
    if (!name) {
      wx.showToast({
        title: '请输入姓名',
        icon: 'none',
      })
      return;
    }
    if (!(/^1[34578]\d{9}$/.test(tel))) {
      wx.showToast({
        title: '请输入正确的手机号码',
        icon: 'none',
      })
      return;
    }

    wx.navigateTo({
      url: './result?carPrice=' + carPrice + "&paymentRatio=" + paymentRatio + "&decoratePrice=" + decoratePrice + "&name=" + name + "&tel=" + tel,
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var user = wx.getStorageSync("user");
    this.setData({
      user: user,
      name:user.name,
      tel:user.tel
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})